<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script lang="javascript">
    //创建正则表达式的两种方法
    // 1.正则表达式字面量
    function searchPhone(phoneNum){
      var re1 = /^[1][3,4,5,7,8][0-9]{9}$/;
      if(re1.test(phoneNum)){
        return true;
      }else{
        return false;
      }
    }
    console.log(searchPhone('18339163091'));

    // 2.调用RegExp对象的构造函数
    function searchName(name){
      var re2 =  new RegExp('^[a-zA-Z0-9_-]{4,16}$');
      
      if(re2.exec(name)){
        return true;
      }else{
        return false;
      }
    }
    console.log(searchName('canshan怕'));
  </script>
</body>
</html>